package com.fly.interceptor;

import com.fly.filter.logincheck;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Slf4j
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    /**
     * 设置静态资源映射
     *
     * @param registry
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("开始进行静态资源映射...");
        registry.addResourceHandler("/backed/**").addResourceLocations("classpath:/backed/");
        registry.addResourceHandler("/templates/backed/**").addResourceLocations("classpath:/templates/backed/");
        registry.addResourceHandler("/plugins/**").addResourceLocations("classpath:/plugins/");
        registry.addResourceHandler("/fronts/**").addResourceLocations("classpath:/fronts/");
        registry.addResourceHandler("/templates/fronts/**").addResourceLocations("classpath:/templates/fronts/");

    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始进行拦截...");
        registry.addInterceptor(new logincheck())
                .addPathPatterns("/**")
                .excludePathPatterns("/admin/login", "/templates/backed/login.html",
                        "/templates/backed/css/**", "/templates/backed/image/**",
                        "/plugins/**", "/templates/backed/js/**" ,
                        "/templates/fronts/plugins/**", "/templates/fronts/pages/**",
                        "/templates/fronts/plugins/js/**","/index/**","/types/**","/frTag/**");
    }


}